package com.ews.onlineexchange.rest;

import com.alibaba.fastjson.JSONObject;
import com.ews.onlineexchange.app.CustomMapper;
import com.ews.onlineexchange.app.NotificationListForApp;
import com.ews.onlineexchange.app.entity.NotificationApp;
import com.ews.onlineexchange.app.entity.TempNotification;
import com.ews.onlineexchange.model.Notification;
import com.ews.onlineexchange.service.NotificationService;
import com.ews.onlineexchange.util.AesUtil;
import com.ews.onlineexchange.util.Result;
import com.fasterxml.jackson.core.JsonProcessingException;

import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonObject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * 山东政务登录接口
 * @author
 *
 */
@Path(value = "/sdzw")
@Transactional
public class SdzwRest {
	@Inject
	EntityManager entityManager;


	@Inject
	NotificationService notificationService;

	private static final String GET_USER_INFO_BY_SDZW_USERNAME = "	"
			+ "	SELECT USERNAME,ALIASP	"
			+ "	FROM SYSTEM_USER su		"
			+ "	WHERE su.SDZWUSERNAME = :sdzwUsername						";
	/**
	 * s
	 * @param username
	 * @return
	 * @throws JsonProcessingException
	 */
	@GET
	@Path("/getInfo/{username}")
	@Produces("application/json")
	@Context
	public Result getInfo(@PathParam("username") String username) throws JsonProcessingException {
		List<Object[]> arrList = (List<Object[]>)entityManager.createNativeQuery(GET_USER_INFO_BY_SDZW_USERNAME).setParameter("sdzwUsername",username).getResultList();
		if(arrList.size() == 0){
			return Result.fail("未找到相关用户！","404");
		}else{
			Object[] arr = arrList.get(0);
			JSONObject data = new JSONObject();
			data.put("s1",arr[0]);
			data.put("s2", AesUtil.AESDecode((String)arr[0],(String)arr[1]));
			return Result.success(data);
		}
	}	
	
}
